package bots.lookahead;

import model.Field;
import model.Figure;
import model.GameType;
import model.MoveChooser;

import java.util.concurrent.ForkJoinPool;

/**
 * @author Alex Vikharev alex.vikharev@gmail.com
 *         created 25.01.12
 */
public class SimpleLookAheadBot extends AbstractLookAheadBot {

    private final int movesToLook;

    public SimpleLookAheadBot(GameType gameType, String name, int movesToLook, ForkJoinPool pool) {
        super(name, gameType, pool);
        this.movesToLook = movesToLook;
    }

    public SimpleLookAheadBot(GameType gameType, String name, int movesToLook, ForkJoinPool pool, MoveChooser chooser) {
        super(name, gameType, pool, chooser);
        this.movesToLook = movesToLook;
    }

    @Override
    public model.Position setFigure(Field field, Figure figure) {
        log.debug("Given: " + figure);
        if (field.getUsedFigures().size() < 2) {
            return setRandomFigure(field, figure);
        } else {
            Task task = new Task(field, figure, movesToLook);
            Result result = pool.invoke(task);
            return result.move;
        }
    }

}
